package baseclass;

import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;

/**
 * Title: class ImageListCellRenderer<br>
 * Description: ImageListCellRenderer class<br>
 * Copyright: MIT open source protocol<br>
 * @author cwll<cwll2009@126.com>
 * @version 1.0.0
 */
public class ImageListCellRenderer extends DefaultListCellRenderer{
	
	private Color rowcolor;
	private int row = -1;
	private int[] rows;
	
	@Override
	public Component getListCellRendererComponent(JList list,
		Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
		DefaultListCellRenderer defaultRenderer=new DefaultListCellRenderer();
		JLabel renderer=(JLabel)defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
		if(value instanceof Object[]){
			Object values[]=(Object[]) value;
			renderer.setIcon((Icon) values[0]);
			renderer.setText((values[1] == null) ? "" : (String) values[1]);
		}
		//super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
		if (rows == null) {
			if (index == row) {
				renderer.setForeground(this.rowcolor);
				setFont(getFont().deriveFont((float) (getFont().getSize() + 2)));
			}
			if (row == -1){
				renderer.setForeground(Color.black);
			}
		} else {
			for (int i = 0; i < rows.length; i++) {
				if (index == rows[i]) {
					renderer.setForeground(this.rowcolor);
					setFont(getFont().deriveFont((float) (getFont().getSize() + 2)));
				}
			}
		}
		return renderer;
	}
	public ImageListCellRenderer(int row, Color color) {
		this.rowcolor = color;
		this.row = row;
	}

	public ImageListCellRenderer(int[] rows, Color color) {
		this.rowcolor = color;
		this.rows = rows;
	}
	public ImageListCellRenderer() {
		this.rowcolor = Color.BLACK;
		//this.rows = rows;
	}
}
